/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.property.buildinfo.service;

import java.util.List;

import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.property.subinfo.entity.PropertyCarinfo;
import com.jeeplus.modules.property.subinfo.entity.PropertyHouseinfo;
import com.jeeplus.modules.property.subinfo.mapper.PropertyCarinfoMapper;
import com.jeeplus.modules.property.subinfo.mapper.PropertyHouseinfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.property.buildinfo.entity.PropertyBuildinginfo;
import com.jeeplus.modules.property.buildinfo.mapper.PropertyBuildinginfoMapper;

/**
 * 楼宇信息Service
 * @author 陈龙
 * @version 2019-01-04
 */
@Service
@Transactional(readOnly = true)
public class PropertyBuildinginfoService extends CrudService<PropertyBuildinginfoMapper, PropertyBuildinginfo> {
	@Autowired
	private PropertyCarinfoMapper propertyCarinfoMapper;
	@Autowired
	private PropertyHouseinfoMapper propertyHouseinfoMapper;
	public PropertyBuildinginfo get(String id) {
		return super.get(id);
	}
	
	public List<PropertyBuildinginfo> findList(PropertyBuildinginfo propertyBuildinginfo) {
		return super.findList(propertyBuildinginfo);
	}
	
	public Page<PropertyBuildinginfo> findPage(Page<PropertyBuildinginfo> page, PropertyBuildinginfo propertyBuildinginfo) {
		return super.findPage(page, propertyBuildinginfo);
	}
	
	@Transactional(readOnly = false)
	public void save(PropertyBuildinginfo propertyBuildinginfo) {
		super.save(propertyBuildinginfo);
	}
	
	@Transactional(readOnly = false)
	public void delete(PropertyBuildinginfo propertyBuildinginfo) {
		super.delete(propertyBuildinginfo);
	}
	@Transactional(readOnly = false)
	public void savehouse(PropertyBuildinginfo propertyBuildinginfo) {
		//propertyBuildinginfo.setPropertyHouseinfoList(propertyHouseinfoMapper.findList(new PropertyHouseinfo(propertyBuildinginfo)));

//		super.save(propertyBuildinginforty);
//		for (PropertyCarinfo propertyCarinfo : propertyBuildinginforty.getPropertyCarinfoList()){
//			if (propertyCarinfo.getId() == null){
//				continue;
//			}
//			if (PropertyCarinfo.DEL_FLAG_NORMAL.equals(propertyCarinfo.getDelFlag())){
//				if (StringUtils.isBlank(propertyCarinfo.getId())){
//					propertyCarinfo.setBuildingid(propertyBuildinginforty);
//					propertyCarinfo.preInsert();
//					propertyCarinfoMapper.insert(propertyCarinfo);
//				}else{
//					propertyCarinfo.preUpdate();
//					propertyCarinfoMapper.update(propertyCarinfo);
//				}
//			}else{
//				propertyCarinfoMapper.delete(propertyCarinfo);
//			}
//		}
		for (PropertyHouseinfo propertyHouseinfo : propertyBuildinginfo.getPropertyHouseinfoList()){
			if (propertyHouseinfo.getId() == null){
				continue;
			}
			if (PropertyHouseinfo.DEL_FLAG_NORMAL.equals(propertyHouseinfo.getDelFlag())){
				if (StringUtils.isBlank(propertyHouseinfo.getId())){
					propertyHouseinfo.setBuildingid(propertyBuildinginfo);
					propertyHouseinfo.preInsert();
					propertyHouseinfoMapper.insert(propertyHouseinfo);
				}else{
					propertyHouseinfo.preUpdate();
					propertyHouseinfoMapper.update(propertyHouseinfo);
				}
			}else{
				propertyHouseinfoMapper.delete(propertyHouseinfo);
			}
		}
	}
    @Transactional(readOnly = false)
    public void savecar(PropertyBuildinginfo propertyBuildinginfo) {
        //propertyBuildinginfo.setPropertyHouseinfoList(propertyHouseinfoMapper.findList(new PropertyHouseinfo(propertyBuildinginfo)));

		for (PropertyCarinfo propertyCarinfo : propertyBuildinginfo.getPropertyCarinfoList()){
			if (propertyCarinfo.getId() == null){
				continue;
			}
			if (PropertyCarinfo.DEL_FLAG_NORMAL.equals(propertyCarinfo.getDelFlag())){
				if (StringUtils.isBlank(propertyCarinfo.getId())){
					propertyCarinfo.setBuildingid(propertyBuildinginfo);
					propertyCarinfo.preInsert();
					propertyCarinfoMapper.insert(propertyCarinfo);
				}else{
					propertyCarinfo.preUpdate();
					propertyCarinfoMapper.update(propertyCarinfo);
				}
			}else{
				propertyCarinfoMapper.delete(propertyCarinfo);
			}
		}

    }
}